package com.jadcon.harveycedars.model.dormitory;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("dormitoryService")
public class DormitoryServiceImpl implements DormitoryService {

	@Autowired
	private DormitoryRepository dormitoryRepository;
	
	public Dormitory getDorm(String name) {
		return dormitoryRepository.getDorm(name);
	}
	
	public Dormitory getDorm(long id) {
		return dormitoryRepository.getDorm(id);
	}

	public List<Dormitory> getDormList() {
		return dormitoryRepository.getDormList();
	}

	public void save(Dormitory dorm) {
		dormitoryRepository.save(dorm);
	}

	public int getTotalBeds() {
		int getTotalBeds = 0;
		for (Dormitory dorm : dormitoryRepository.getDormList()) {
			getTotalBeds = getTotalBeds + dorm.getTotalBeds();	
		}
			return getTotalBeds;
	}

	public int getTotalBedsAvailable() {
		int getTotalBedsAvailable = 0;
		for (Dormitory dorm : dormitoryRepository.getDormList()) {
			getTotalBedsAvailable = getTotalBedsAvailable + dorm.getBedsAvailable();
		}
		return getTotalBedsAvailable;
	}
	

	public int getTotalGuests() {
		int getTotalGuests = 0;
		for (Dormitory dorm : dormitoryRepository.getDormList()){
			getTotalGuests = getTotalGuests + dorm.getTotalGuest();
		}
		return getTotalGuests;
	}
	

	
	
}
